/* -----------------------------------------------------------------------
 * Lindsay Ergenekan
 * Demonstration of how to write unit tests for dominion-base
 * 
 * This unit tests whether each player is playing the correct player's hand is updated
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include "interface.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1



//#define _DOMINION_H 

int main() {
    int i;
    int seed = 1000;
    int numPlayer = 2;
    int maxBonus = 10;
    int p, r, handCount;
    int bonus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
    // arrays of all coppers, silvers, and golds
    int coppers[MAX_HAND];
    int silvers[MAX_HAND];
    int golds[MAX_HAND];
//variable for the number of players
//variable to test if each player has played the correct number of time
	
    for (i = 0; i < MAX_HAND; i++)
    {
        coppers[i] = copper;
        silvers[i] = silver;
        golds[i] = gold;
    }

                memset(&G, 23, sizeof(struct gameState));   // clear the game state
                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game


    printf ("TESTING updateCoins():\n");
    for (p = 0; p < numPlayer; p++)
    {
        G.handCount[p] = handCount;                 // set the number of cards on hand
        memcpy(G.hand[p], coppers, sizeof(int) * handCount); // set all the cards to copper
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {
            for (bonus = 0; bonus <= maxBonus; bonus++)
            {
#if (NOISY_TEST == 1)
                printf("Player (%d) Bonus (%d) Handcount (%d) \n", p, bonus, handCount);
#endif
 //               memset(&G, 23, sizeof(struct gameState));   // clear the game state
 //               r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
 //               G.handCount[p] = handCount;                 // set the number of cards on hand
 //               memcpy(G.hand[p], coppers, sizeof(int) * handCount); // set all the cards to copper
                updateCoins(p, &G, bonus);
//				assert(G.whoseTurn == p); //check if the correct player is updated
				
#if (NOISY_TEST == 1)
                printf("player(i) (%d) expected (%d) bonus(%d), handcount (%d) \n", p, handCount + bonus, handCount, bonus);
               printf("player (%d) G.coins(i) (%d), bonus(%d), handcount (%d)\n", p,  G.whoseTurn, G.coins, G.handCount[G.whoseTurn]);

#endif
 //               assert(G.coins == handCount * 1 + bonus); // check if the number of coins is correct
//				assert(G.whoseTurn == p); //check if the correct player is updated

                memcpy(G.hand[p], silvers, sizeof(int) * handCount); // set all the cards to silver
                updateCoins(p, &G, bonus);
 
#if (NOISY_TEST == 1)
                printf("player %d has G.coins = %d, %d expected = %d\n", p, G.coins, G.whoseTurn, handCount * 1 + bonus);
#endif
 //               assert(G.coins == handCount * 2 + bonus); // check if the number of coins is correct
//				assert(G.whoseTurn == p); //check if the correct player is updated

                memcpy(G.hand[p], golds, sizeof(int) * handCount); // set all the cards to gold
                updateCoins(p, &G, bonus); 
#if (NOISY_TEST == 1)
                printf("player %d has G.coins = %d, %d expected = %d\n", p, G.coins, G.whoseTurn, handCount * 1 + bonus);
#endif
//			assert(G.coins == handCount * 3 + bonus); // check if the number of coins is correct 
//			assert(G.whoseTurn == p); //check if the correct player is updated			
			}
			
#if (NOISY_TEST == 1)
                printf("player %d has G.coins = %d, %d expected = %d\n", p, G.coins, G.whoseTurn, handCount * 1 + bonus);
#endif			
 
		}
     
    }
//    printf("All tests passed!\n");

    return 0;
}
